#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;

long long merge_sort(long long a[],long long temp[],long long L,long long R){
	if( L==R ) return 0;
	long long mid = (L + R)/2;
	long long ret = merge_sort(a,temp,L,mid) + merge_sort(a,temp,mid+1,R);
	long long c = L;
	long long i=L,j=mid+1;
	for(; i<=mid && j<=R;){
		if(a[i]>a[j] ){
			temp[c++] = a[i++];
			ret += R-j+1;
		} else temp[c++] = a[j++];
	}
	if( i==mid+1 ) memcpy(temp+c,a+j,(R-j+1)*sizeof(long long));
	if( j==R+1 ) memcpy(temp+c,a+i,(mid-i+1)*sizeof(long long));
	memcpy(a+L,temp+L,(R-L+1)*sizeof(long long));
	return ret;
}
int main(){
	long long n,m;
	cin >> n;
	long long len = pow(2,n);
	long long *a = new long long[len],*b = new long long[len],*temp = new long long[len];
	for(long long i=0; i<len; i++ ) scanf("%lld",a+i);
	cin >> m;
	long long pre = -1;
	for(long long i=0; i<m; i++){
		long long t;
	    scanf("%lld",&t);
		long long size = pow(2,t);
		if( pre==-1 || size!=1 ){
			for(long long i=0; i<len/size; i++){
				reverse(a+i*size,a+(i+1)*size);
			} 
			memcpy(b,a,len*sizeof(long long));
			pre = merge_sort(b,temp,0,len-1);
			printf("%lld\n",pre);
		}else printf("%lld\n",pre);
	}
	delete[] a,b,temp;
	return 0;
}
